package pl.edu.mimuw.irs.rcp.controller.editor.workflow.command;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.gef.requests.BendpointRequest;

import pl.edu.mimuw.irs.core.util.RelativePosition;

public class MoveBendpointCommand extends AbstractBendpointCommand {

	// *** Attributes
	
	private RelativePosition oldPosition;
	public RelativePosition getOldPosition() {
		return oldPosition;
	}
	public void setOldPosition(RelativePosition oldPosition) {
		this.oldPosition = oldPosition;
	}
	
	// *** Constructors
	
	public MoveBendpointCommand(BendpointRequest request) {
		super(request);
		setOldPosition(getArc().getVertices().get(getIndex()));
	}

	// *** Methods
	
	@Override
	public void execute() {
		List<RelativePosition> vertices = 
			new ArrayList<RelativePosition>(getArc().getVertices());
		vertices.set(getIndex(), getPosition());
		getArc().setVertices(vertices);
		super.execute();
	}
	
	@Override
	public void undo() {
		List<RelativePosition> vertices = 
			new ArrayList<RelativePosition>(getArc().getVertices());
		vertices.set(getIndex(), getOldPosition());
		getArc().setVertices(vertices);
		super.undo();
	}
}
